package com.four.basicinfo.service.impl;

import com.four.basicinfo.code.Page;
import com.four.basicinfo.dao.InformationDao;
import com.four.basicinfo.entity.Information;
import com.four.basicinfo.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationServiceImpl implements InformationService {
    @Autowired
    InformationDao informationDao;
    /**
     * 查询基本信息列表
     *
     * @return 基本信息
     */
    public Page<Information> getOnrePage(int pageNum, int pageSize, String name, Integer number,
                                         String sex, String employee,
                                         String grade, String duties,
                                         String education, String marriage){
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Information> list=informationDao.canInformation(start,pageSize,name,number,sex,employee,grade,duties,education,marriage);
        //获取总条目数
        int total=informationDao.countInformation(name,number,sex,employee,grade,duties,education,marriage);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Information> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }
    /**
     * 查询基本信息
     *
     * @param id 基本信息主键
     * @return 基本信息
     */
    @Override
    public Information selectInformationById(Long id)
    {
        return informationDao.selectInformationById(id);
    }

    /**
     * 修改基本信息
     *
     * @param information 基本信息
     * @return 结果
     */
    @Override
    public Boolean updateInformation(Information information)
    {
        return informationDao.updateInformation(information)>0;
    }

}
